﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace FasterWPF
{
    public static class DockPanelExt
    {
        public static DockPanel SetBackgroundColor(this DockPanel chain, Brush brush)
        {
            Brush newBrush = (brush);
            chain.Background = newBrush;
            return chain;
        }

        public static DockPanel Initialize(this DockPanel source, ContainerType containerType, int? rowSpan, int? colSpan)
        {
            if (rowSpan != null)
            {
                Grid.SetRowSpan(source, (int)rowSpan);
            }

            if (colSpan != null)
            {
                Grid.SetColumnSpan(source, (int)colSpan);
            }

            return Initialize(source, double.NaN, double.NaN, containerType); //Default width and height to Auto by setting to NaN
        }

        public static DockPanel Initialize(this DockPanel source, double width, double height, ContainerType containerType, int? rowSpan, int? colSpan)
        {
            if (rowSpan != null)
            {
                Grid.SetRowSpan(source, (int)rowSpan);
            }

            if (colSpan != null)
            {
                Grid.SetColumnSpan(source, (int)colSpan);
            }

            return Initialize(source, width, height, containerType); //Default width and height to Auto by setting to NaN
        }

        public static DockPanel Initialize(this DockPanel source, double width, double height, ContainerType containerType)
        {
            //Force the Aero theme by default to assure the structure of the Listbox
            Uri uri = new Uri("/PresentationFramework.Aero;component/themes/Aero.NormalColor.xaml", UriKind.Relative);
            source.Resources.MergedDictionaries.Add(Application.LoadComponent(uri) as ResourceDictionary);

            source.Width = width;
            source.Height = height;
            source.SetContainerType(containerType);

            IComposite icomp = CompositeTypeHelper.CreateIComposite<DockPanel>(source);
            source.SetIComposite<DockPanel>(icomp);

            //STORE SETTING BUILD CHAIN AND GET CHAIN?!?  Put these in a Composite implements an interface
            DockPanelParent dbsr = new DockPanelParent();
            source.StoreSetting<DockPanel>("IParent", dbsr);

            source.AddItemBorder(Brushes.Gray, new Thickness(1, 1, 1, 1)); //default Border     
            source.StoreSetting<DockPanel>("BorderSettings", new BorderSettings() { Width = double.NaN, Height = double.NaN, BorderBrush = Brushes.Gray, BorderThickness = new Thickness(0, 0, 0, 0), CornerRadius = new CornerRadius(0), Padding = new Thickness(0) });

            return source;
        }

    }//end of class
}//end of namespace
